from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest

AK = "LTAI4G7emXUN3dnGVK2p1duM===="
SK = "ZgekQkkT1cZZ4hCyhSquxOwwnjyfLo===="


def send_message(phone, code):
    # 登录阿里云客户端
    client = AcsClient(AK, SK, 'cn-hangzhou')

    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', str(phone))
    request.add_query_param('SignName', "<签名>")
    request.add_query_param('TemplateCode', "<模板名>")
    request.add_query_param('TemplateParam', str({'code': code}))

    response = client.do_action(request)
    print(str(response, encoding='utf-8'))
